<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/%E6%AD%A6%E6%B1%8932x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/%E6%AD%A6%E6%B1%8916x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib1/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="/lib1/pace/pace-theme-center-simple.min.css">
  <script src="/lib1/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="前言现在自己所用的技术栈基本都是vue2.0，之前有了解过vue的基本原理，即：数据劫持、收集依赖、派发更新。但具体的实现过程并没有去深究，这里想尝试去的去了解下vue2的源码，看看到底是如何实现的。由于自己的水平有限，可能不能深入地进行分析，只能简要说明源码各部分的用法跟自己的理解吧。第一篇中主要想解释下vue的初始化与其响应式配置的源码。 vue初始化platforms&#x2F;web&#x2F;entry-r">
<meta property="og:type" content="article">
<meta property="og:title" content="vue源码分析(一)">
<meta property="og:url" content="http://example.com/2021/03/16/vue%E6%BA%90%E7%A0%81/vue%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90(%E4%B8%80)/index.html">
<meta property="og:site_name" content="Technological Blog">
<meta property="og:description" content="前言现在自己所用的技术栈基本都是vue2.0，之前有了解过vue的基本原理，即：数据劫持、收集依赖、派发更新。但具体的实现过程并没有去深究，这里想尝试去的去了解下vue2的源码，看看到底是如何实现的。由于自己的水平有限，可能不能深入地进行分析，只能简要说明源码各部分的用法跟自己的理解吧。第一篇中主要想解释下vue的初始化与其响应式配置的源码。 vue初始化platforms&#x2F;web&#x2F;entry-r">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-03-16T04:18:39.000Z">
<meta property="article:modified_time" content="2021-05-14T07:35:29.774Z">
<meta property="article:author" content="Li Yudong">
<meta property="article:tag" content="vue源码">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://example.com/2021/03/16/vue%E6%BA%90%E7%A0%81/vue%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90(%E4%B8%80)/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>vue源码分析(一) | Technological Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Technological Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">IT小白的成长之旅</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="tags fa-fw"></i>标签<span class="badge">18</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="th fa-fw"></i>分类<span class="badge">14</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="archive fa-fw"></i>归档<span class="badge">95</span></a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/tiarmor1" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/03/16/vue%E6%BA%90%E7%A0%81/vue%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90(%E4%B8%80)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/author.jpg">
      <meta itemprop="name" content="Li Yudong">
      <meta itemprop="description" content="">
    </span>
    
    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Technological Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          vue源码分析(一)
        </h1>
    
        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
    
              <time title="创建时间：2021-03-16 12:18:39" itemprop="dateCreated datePublished" datetime="2021-03-16T12:18:39+08:00">2021-03-16</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-05-14 15:35:29" itemprop="dateModified" datetime="2021-05-14T15:35:29+08:00">2021-05-14</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/VUE/" itemprop="url" rel="index"><span itemprop="name">VUE</span></a>
                </span>
            </span>
    
          
    
        </div>
      </header>
    
    
    
    
    <div class="post-body" itemprop="articleBody">
    
      
        <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>现在自己所用的技术栈基本都是vue2.0，之前有了解过vue的基本原理，即：数据劫持、收集依赖、派发更新。但具体的实现过程并没有去深究，这里想尝试去的去了解下vue2的源码，看看到底是如何实现的。由于自己的水平有限，可能不能深入地进行分析，只能简要说明源码各部分的用法跟自己的理解吧。第一篇中主要想解释下<strong>vue的初始化与其响应式配置</strong>的源码。</p>
<h1 id="vue初始化"><a href="#vue初始化" class="headerlink" title="vue初始化"></a>vue初始化</h1><h3 id="platforms-web-entry-runtime-with-compiler-js"><a href="#platforms-web-entry-runtime-with-compiler-js" class="headerlink" title="platforms/web/entry-runtime-with-compiler.js"></a><strong>platforms/web/entry-runtime-with-compiler.js</strong></h3><p>不管你在初始化vue实例时，使用的是template、el、还是render函数，其判定的优先级是render &gt; template &gt; le。且这段代码会根据你使用的不同方式，采取不同的处理方法，最终都会得到渲染函数，也就是一个render方法，再将render函数放置在opions.render中。<strong>其实实现的就是扩展了$mount方法，能够处理el和template，执行模板解析与编译工作</strong></p>
<h3 id="platforms-web-runtime-index-js"><a href="#platforms-web-runtime-index-js" class="headerlink" title="platforms/web/runtime/index.js"></a><strong>platforms/web/runtime/index.js</strong></h3><p>1、安装web平台特有指令和组件；</p>
<p>2、实现<strong>patch方法</strong>：补丁函数，把用户传入的虚拟DOM转换成为真实DOM，其实只有2种执行情景：初始化时的赋值、每次用户更新DOM时的diff算法。</p>
<p>3、实现**$mount**：一般我们使用$mount就是传入一个宿主文件，将vue挂载在该宿主文件上。该功能就是初始化，然后将首次渲染的结果来替换el。</p>
<h3 id="core-index-js"><a href="#core-index-js" class="headerlink" title="core/index.js"></a><strong>core/index.js</strong></h3><p><strong>初始化全局api</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">Vue.set = <span class="keyword">set</span> </span><br><span class="line">Vue.delete = del </span><br><span class="line">Vue.nextTick = nextTick </span><br><span class="line">initUse(Vue) // 实现Vue.use函数 </span><br><span class="line">initMixin(Vue) // 实现Vue.mixin函数 </span><br><span class="line">initExtend(Vue) // 实现Vue.extend函数 </span><br><span class="line">initAssetRegisters(Vue) // 注册实现Vue.component/directive/filter</span><br></pre></td></tr></table></figure>

<h3 id="core-instance-index-js"><a href="#core-instance-index-js" class="headerlink" title="core/instance/index.js"></a><strong>core/instance/index.js</strong></h3><p>该文件定义了vue的构造函数方法，其实只是执行了this._init方法。</p>
<p>同时定义了并混入了很多的实例方法：1、和状态相关的实例方法stateMixin中的$set、$delete、$watch、$data、$props。2、事件相关的方法：$on、$once、$off、$emit。3、生命周期相关的方法。4、渲染函数相关的方法。$nextTick：什么时候用，做了一个操作，同时你想立刻看到数据的结果，则你必须写在$nextTick的回调函数中，因为vue是一个异步更新的框架。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Vue</span> (<span class="params">options</span>) </span>&#123; </span><br><span class="line"><span class="comment">// 构造函数仅执行了_init </span></span><br><span class="line"><span class="keyword">this</span>._init(options) </span><br><span class="line">&#125;</span><br><span class="line">initMixin(Vue) <span class="comment">// 实现init函数,通过该方法给vue添加_init方法。</span></span><br><span class="line">stateMixin(Vue) <span class="comment">// 状态相关api $data,$props,$set,$delete,$watch </span></span><br><span class="line">eventsMixin(Vue)<span class="comment">// 事件相关api $on,$once,$off,$emit </span></span><br><span class="line">lifecycleMixin(Vue) <span class="comment">// 生命周期api _update,$forceUpdate,$destroy </span></span><br><span class="line">renderMixin(Vue)<span class="comment">// 渲染api _render,$nextTick</span></span><br></pre></td></tr></table></figure>

<h3 id="core-instance-init-js"><a href="#core-instance-init-js" class="headerlink" title="core/instance/init.js"></a><strong>core/instance/init.js</strong></h3><p>创建组件实例的init方法的定义，初始化其数据、属性、事件等</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">initLifecycle(vm) </span><br><span class="line"><span class="comment">// $parent,$root,$children,$refs 设置跟生命周期相关的变量，</span></span><br><span class="line"><span class="comment">//先设置父组件、祖先组件，因此组件创建的顺序是自上而下的，但挂载的顺序是自下而上的。</span></span><br><span class="line">initEvents(vm) </span><br><span class="line"><span class="comment">//添加监听父组件传递的事件和回调，因为事件谁派发，谁监听，事件本身就是子组件在派发。</span></span><br><span class="line">initRender(vm)</span><br><span class="line"><span class="comment">//render(h) 此处的$createElement就是h;</span></span><br><span class="line"><span class="comment">//声明$slots,$scopedSlots,_c,$createElement，在此初始化插槽内容。</span></span><br><span class="line">callHook(vm, <span class="string">'beforeCreate'</span>)</span><br><span class="line"><span class="comment">//调用beforeCreate钩子</span></span><br><span class="line">initInjections(vm) <span class="comment">// 获取注入数据,依赖注入</span></span><br><span class="line">initState(vm) </span><br><span class="line"><span class="comment">// 初始化props，methods，data，computed，watch，同时实现响应式。</span></span><br><span class="line">initProvide(vm) <span class="comment">// 提供数据注入，注入的数据是不会做响应式的</span></span><br><span class="line">callHook(vm, <span class="string">'created'</span>)</span><br></pre></td></tr></table></figure>

<h3 id="core-instance-lifecycle-js"><a href="#core-instance-lifecycle-js" class="headerlink" title="core/instance/lifecycle.js**"></a>core/instance/lifecycle.js**</h3><p><strong>mountComponent</strong>：声明了updateComponent，且创建了一个与组件相关的Watcher。</p>
<p><strong>render</strong>：渲染组件，调用用户定义的render方法，获取vdom</p>
<p><strong>updateComponent</strong>：执行更新，将传入的</p>
<p>5-vdom转换为dom，初始化时执行的是dom创建操作，在任何组件发生变化时，updateComponent该函数都会重新再执行一次。</p>
<h3 id="总体流程"><a href="#总体流程" class="headerlink" title="总体流程"></a><strong>总体流程</strong></h3><p>new Vue()：调用init =&gt; _init()：初始化各种属性 =&gt; $mount()：调用mountComponent =&gt; mountComponent：声明了一个updateComponent函数，并创建一个和组件相关的Watcher =&gt; render()：获取虚拟DOM =&gt; update(Component)：把虚拟DOM转换为真实DOM</p>
<h1 id="数据响应式"><a href="#数据响应式" class="headerlink" title="数据响应式"></a>数据响应式</h1><h3 id="src-core-instance-state-js"><a href="#src-core-instance-state-js" class="headerlink" title="src\core\instance\state.js"></a><strong>src\core\instance\state.js</strong></h3><p>初始化数据，包括props、methods、data、computed和watch。</p>
<p>核心代码<strong>initData</strong>将data数据响应化，即代理这些数据到实例上，同时会判断是否有重复。</p>
<h3 id="core-observer-index-js"><a href="#core-observer-index-js" class="headerlink" title="core/observer/index.js"></a><strong>core/observer/index.js</strong></h3><p>observe方法返回一个Observer实例。如果已经存在则直接返回，不存在则新建实例对象。每一个响应式的数据对象，都会被附加上一个Observer来进行监听。</p>
<p>Observer对象根据数据类型执行对应的响应化操作，在保存值得同时，还会额外生成一个dep。DEP的用法：1、我们操作数组通常使用push、pop、splice等方法，此时是没有办法得知数组的变化的，这时候vue采取的策略是拦截这些方法，并通知对应dep。2、object里面新增或者删除属性，同样也会通知dep。</p>
<p>defineReactive定义对象属性的getter/setter，getter负责添加依赖，setter负责通知更新。如果有依赖存在，则收集依赖，同时会查询是否存在子ob，子ob也会收集这个依赖，同时如果值是数组，同样要将其所有项均添加依赖。有几个key就会有几个dep，Watcher一个组件只会有1个，Observer一个对象就会有一个。</p>
<h3 id="core-observer-dep-js"><a href="#core-observer-dep-js" class="headerlink" title="core/observer/dep.js"></a><strong>core/observer/dep.js</strong></h3><p>Dep负责管理一组Watcher，包括watcher实例的增删及通知更新</p>
<h3 id="Watcher"><a href="#Watcher" class="headerlink" title="Watcher"></a><strong>Watcher</strong></h3><p>Watcher解析一个表达式并收集依赖，当数值变化时触发回调函数，常用于$watch API和指令中。</p>
<p>有对应的Watcher，数值变化会触发其update函数导致重新渲染。相关API： $watcher</p>
<h3 id="src-core-observer-array-js"><a href="#src-core-observer-array-js" class="headerlink" title="src\core\observer\array.js"></a><strong>src\core\observer\array.js</strong></h3><p>数组数据变化的侦测跟对象不同，我们操作数组通常使用push、pop、splice等方法，此时没有办法得知数据变化。所以vue中采取的策略是拦截这些方法并通知dep。为数组原型中的7个可以改变内容的方法定义拦截器<strong>Observer****中覆盖数组原型</strong></p>
<h3 id="vue2-0响应式的缺点："><a href="#vue2-0响应式的缺点：" class="headerlink" title="vue2.0响应式的缺点："></a>vue2.0响应式的缺点：</h3><p>1、递归、循环遍历比较多，性能会收到影响，因此vue3.0使用proxy来代替，只用在外面加上一层代理。</p>
<p>2、API不统一，对于数组与对象采取的是两套方法来进行实现。</p>

    </div>
    
    
    
    
    <div>
      
        <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>

      
    </div>
        <div class="reward-container">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/images/alipay.png" alt="Li Yudong 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>

        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Li Yudong
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://example.com/2021/03/16/vue%E6%BA%90%E7%A0%81/vue%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90(%E4%B8%80)/" title="vue源码分析(一)">http://example.com/2021/03/16/vue源码/vue源码分析(一)/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

    
      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/vue%E6%BA%90%E7%A0%81/" rel="tag"># vue源码</a>
          </div>
    
        

    
        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/03/12/%E5%AD%A6%E6%A0%A1%E9%A1%B9%E7%9B%AE%E5%BA%94%E7%94%A8/%E9%A6%96%E5%B1%8F%E4%BC%98%E5%8C%96%E5%AE%9E%E8%B7%B5/" rel="prev" title="首屏优化实践">
      <i class="fa fa-chevron-left"></i> 首屏优化实践
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/03/17/vue%E6%BA%90%E7%A0%81/vue%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90(%E4%BA%8C)/" rel="next" title="vue源码分析(二)">
      vue源码分析(二) <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#vue初始化"><span class="nav-number">2.</span> <span class="nav-text">vue初始化</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#platforms-web-entry-runtime-with-compiler-js"><span class="nav-number">2.0.1.</span> <span class="nav-text">platforms&#x2F;web&#x2F;entry-runtime-with-compiler.js</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#platforms-web-runtime-index-js"><span class="nav-number">2.0.2.</span> <span class="nav-text">platforms&#x2F;web&#x2F;runtime&#x2F;index.js</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#core-index-js"><span class="nav-number">2.0.3.</span> <span class="nav-text">core&#x2F;index.js</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#core-instance-index-js"><span class="nav-number">2.0.4.</span> <span class="nav-text">core&#x2F;instance&#x2F;index.js</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#core-instance-init-js"><span class="nav-number">2.0.5.</span> <span class="nav-text">core&#x2F;instance&#x2F;init.js</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#core-instance-lifecycle-js"><span class="nav-number">2.0.6.</span> <span class="nav-text">core&#x2F;instance&#x2F;lifecycle.js**</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#总体流程"><span class="nav-number">2.0.7.</span> <span class="nav-text">总体流程</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#数据响应式"><span class="nav-number">3.</span> <span class="nav-text">数据响应式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#src-core-instance-state-js"><span class="nav-number">3.0.1.</span> <span class="nav-text">src\core\instance\state.js</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#core-observer-index-js"><span class="nav-number">3.0.2.</span> <span class="nav-text">core&#x2F;observer&#x2F;index.js</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#core-observer-dep-js"><span class="nav-number">3.0.3.</span> <span class="nav-text">core&#x2F;observer&#x2F;dep.js</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Watcher"><span class="nav-number">3.0.4.</span> <span class="nav-text">Watcher</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#src-core-observer-array-js"><span class="nav-number">3.0.5.</span> <span class="nav-text">src\core\observer\array.js</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#vue2-0响应式的缺点："><span class="nav-number">3.0.6.</span> <span class="nav-text">vue2.0响应式的缺点：</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Li Yudong"
      src="/images/author.jpg">
  <p class="site-author-name" itemprop="name">Li Yudong</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">95</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">18</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/tiarmor1" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;tiarmor1" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:1157019137@qq.com" title="E-Mail → mailto:1157019137@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>
  <div class="cc-license motion-element" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 2020 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Li Yudong</span>
</div>

        








      </div>
    </footer>
  </div>

  
  
  <script color='0,0,0' opacity='0.5' zIndex='-1' count='150' src="/lib1/canvas-nest/canvas-nest.min.js"></script>
  <script src="/lib1/anime.min.js"></script>
  <script src="/lib1/velocity/velocity.min.js"></script>
  <script src="/lib1/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  

  
   <canvas class="fireworks" style="position: fixed;left: 0;top: 0;z-index: 1; pointer-events: none;" ></canvas> 
   <script type="text/javascript" src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script> 
   <script type="text/javascript" src="/js/fireworks.js"></script>
  
</body>
</html>

